package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.activity.client.SeckillGoodsFeignClient;
import com.atguigu.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class SeckillController {
    @Autowired
    private SeckillGoodsFeignClient seckillGoodsFeignClient;

    //秒杀频道首页
    @GetMapping("/index")
    public String index(Model model) {
        List<SeckillGoods> list = seckillGoodsFeignClient.list();
        model.addAttribute("list", list);
        return "seckill/index";
    }

    //秒杀的详情页
    @GetMapping("/seckill/{skuId}.html")
    public String seckillDetail(Model model, @PathVariable String skuId) {
        SeckillGoods item = seckillGoodsFeignClient.item(skuId);
        model.addAttribute("item", item);
        return "seckill/item";
    }

    //进入秒杀抢购页面
    @GetMapping("/seckill/queue.html")
    public String seckillQueue(Long skuId, String skuIdStr, Model model) {
        model.addAttribute("skuId",skuId);
        model.addAttribute("skuIdStr",skuIdStr);
        return "seckill/queue";
    }
}
